﻿
using System;
using System.ComponentModel.DataAnnotations;

namespace JT.Domain
{
    public class Message
    {
        public int Id { get; set; }
        public int Count { get; set; }
        [Display(Name = "标题"), Required(ErrorMessage = "{0}不能为空")]
        //[RegularExpression(@"^[A-Za-z0-9_.-]+@([A-Za-z0-9]+\.[A-Za-z0-9]+){1,3}$")]
        public string Title { get; set; }
        [Display(Name = "内容"), Required(ErrorMessage = "{0}不能为空")]
        public string Content { get; set; }
        [Display(Name = "消息级别"), Required(ErrorMessage = "{0}不能为空")]
        public EMSLevel? MSLevel { get; set; } //消息级别
        public bool Processed { get; set; } //是否处理
        public bool Read { get; set; } //是否阅读

        public DateTime SendTime { get; set; } = DateTime.Now;
        //public JTWEB3User Applicant { get; set; }

    }
    public enum EMSLevel
    {

        [Display(Name = "系统消息")]
        SystemMassage,
        [Display(Name = "评论回复")]
        CommentReply,
        [Display(Name = "工作通知")]
        WorkNotice,
        [Display(Name = "@我的")]
        AtMe,
        [Display(Name = "")]
        None,
    }

    public class MSLevel
    {
        public int Id { get; set; }
        public string SystemMessage { get; set; }

        public string CommentReply { get; set; }
        public string WorkNotice { get; set; }
        public string AtMe { get; set; }
    }
    //public class IsEnumAttribute : ValidationAttribute
    //{
    //    //向构造函数中传递一个默认的错误提示消息，包含一个参数占位符{0}
    //    public IsEnumAttribute() : base("你输入的内容不是{0}.")
    //    {

    //    }
    //    //第一个参数是验证对象的值
    //    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    //    {
    //        //if (value != null)
    //        //{
    //        //var valueAsString = value.ToString();
    //        //if (valueAsString.Split(' ').Length > _isEnum)
    //        //{
    //        //    //FormatErrorMessage方法会自动使用显示的属性名称来格式化这个字符串
    //        //    var errorMessage = FormatErrorMessage(validationContext.DisplayName);
    //        //    return new ValidationResult(errorMessage);
    //        //}

    //        if (value is EMSLevel)
    //        {
    //            return ValidationResult.Success;
    //        }
    //        //FormatErrorMessage方法会自动使用显示的属性名称来格式化这个字符串
    //        var errorMessage = FormatErrorMessage(validationContext.DisplayName);
    //        return new ValidationResult(errorMessage);
    //    }
    //    //private readonly int _isEnum;
    //}


}
